
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

void TestPthreadJoin();

void * ThreadFunction(void * parameter);

// build : gcc -Wall -Wshadow -g pthread_test.c -o pthread_test -lpthread
int main(int argc, char * argv[]) {

    TestPthreadJoin();

    return EXIT_SUCCESS;
}

void TestPthreadJoin() {

    pthread_t tid;
    pthread_create(&tid, NULL, ThreadFunction, NULL);
    pthread_join(tid, NULL);
    printf("waiting\n");
}

void * ThreadFunction(void * parameter) {

    printf("sleeping ......\n");    // no input
    sleep(4);
    return NULL;
}

void * ThreadFunctionTwo(void * paramter) {

    // 分离式
    pthread_detach(pthread_self());

    return NULL;
}

void * ThreadFunctionThree(void * parameter) {

    
    // pthread_exit stand for return

    // the parameter is the result 
    pthread_exit(NULL);
}